"""
验证修改个人资料_合法修改用户名为最小限制
"""
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.support.select import Select

#打开浏览器
driver=webdriver.Chrome()
#打开悟空CRM
driver.get("http://192.168.1.83/crm/index.php?m=user&a=login")
driver.maximize_window()

#数据
username="lisi"
passwword="123456"
alert_name="l"
user_classes_value="1"
account_status_value="0"
defpartment_value="1"
role_value="1"
email="1554162506@qq.com"
phonenumber="18281993022"
address="成都"


#进入个人资料定位器
username_locator=(By.NAME,"name")
password_locator=(By.NAME,"password")
login_locator=(By.NAME,"submit")
touxiang_locator=(By.XPATH,"/html/body/div[1]/div/div/div[2]/ul[2]/li[6]/a/img")
personal_data_btn_locator=(By.LINK_TEXT,"个人资料")

#输入个人资料信息
name_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(4) > td:nth-child(2) > input[type=text]")
user_classes_locator=(By.ID,"category_id")
account_status_locator=(By.ID,"status")
defpartment_locator=(By.ID,"department")
role_locator=(By.ID,"role")
man_locator=(By.XPATH,"/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[10]/td[2]/input[1]")
woman_locator=(By.XPATH,"/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[10]/td[2]/input[2]")
email_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(11) > td:nth-child(2) > input")
phone_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(12) > td:nth-child(2) > input")
contactaddress_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(13) > td:nth-child(2) > textarea")
save_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(2) > form > table > tfoot > tr > td:nth-child(2) > input.btn.btn-primary")


#成功登录
driver.find_element(*username_locator).send_keys(username)
driver.find_element(*password_locator).send_keys(passwword)
driver.find_element(*login_locator).click()
sleep(2)
#点击头像
driver.find_element(*touxiang_locator).click()
#在下拉框选择个人资料
driver.find_element(*personal_data_btn_locator).click()
#清理用户名输入框
driver.find_element(*name_locator).clear()
#输入长度为1的用户名
driver.find_element(*name_locator).send_keys(alert_name)
#用户类别选择框在选择第一个类别
a=driver.find_element(*user_classes_locator)
Select(a).select_by_value(user_classes_value)
#账号状态选择框选择第一个状态
b=driver.find_element(*account_status_locator)
Select(b).select_by_value(account_status_value)\
#部门选择框选择第一个
c=driver.find_element(*defpartment_locator)
Select(c).select_by_value(defpartment_value)
#清理邮箱输入框
driver.find_element(*email_locator).clear()
#输入新邮箱
driver.find_element(*email_locator).send_keys(email)
#清理手机输入框
driver.find_element(*phone_locator).clear()
#输入新手机号码
driver.find_element(*phone_locator).send_keys(phonenumber)
#清理联系地址
driver.find_element(*contactaddress_locator).clear()
#输入新联系地址
driver.find_element(*contactaddress_locator).send_keys(address)
#点击保存
driver.find_element(*save_locator).click()

sleep(3)
driver.quit()